<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSX事件绑定-参数</title>
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.getElementById('root'))

    class App extends React.Component {
        constructor(props) {
            super();
            this.state = {
                message: "",
            }
        }

        btnClick = function(flag, event) {
            console.log(flag, event)
            this.setState({
                message: event + ''
            })
        }
        render() {
            return (
                <div>
                    <h1>JSX事件绑定-参数</h1>
                    <h5>{this.state.message}</h5>
                    {/* 注意，这种方式绑定，event为方法最后一个参数.ann */}
                    <button onClick={this.btnClick.bind(this, 'Click1')}>Click1</button>
                    <button onClick={(event) => this.btnClick('Click2', event)}>Click2</button>
                </div>
            )
        }
    }
    root.render(<App />);
</script>
</body>
</html>